<html>
    <head>
        <title>Itowns - Planar kml + geojson file example</title>

        <meta charset="UTF-8">
        <link rel="stylesheet" type="text/css" href="css/example.css">
        <link rel="stylesheet" type="text/css" href="css/loading_screen.css">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div class="help">
            <p>Key bindings</p>
            <ul>
              <li>Left-Click: camera translation (drag)</li>
              <li>Right-Click: camera translation (pan)</li>
              <li>Ctrl + Left-Click: camera rotation (orbit)</li>
              <li>Spacebar / Wheel-Click: smart zoom</li>
              <li>Mouse Wheel: zoom in/out</li>
              <li>T: orient camera to a top view</li>
              <li>Y: move camera to start position</li>
            </ul>
        </div>
        <div id="viewerDiv"></div>
        <script src="../dist/itowns.js"></script>
        <script src="js/loading_screen.js"></script>
        <script src="js/proj4defs/3946.js"></script>
        <script type="text/javascript">
            // # Planar (EPSG:3946) viewer

            var extent;
            var viewerDiv;
            var view;
            var p;
            var config;

            // Define geographic extent: CRS, min/max X, min/max Y
            extent = new itowns.Extent(
                'EPSG:3946',
                1837816.94334, 1847692.32501,
                5170036.4587, 5178412.82698);

            // `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
            viewerDiv = document.getElementById('viewerDiv');

            // Instanciate PlanarView*
            view = new itowns.PlanarView(viewerDiv, extent, { disableSkirt: true });
            setupLoadingScreen(viewerDiv, view);

            // Add a WMS imagery source
            var wmsImagerySource = new itowns.WMSSource({
                extent: extent,
                name: 'Ortho2009_vue_ensemble_16cm_CC46',
                url: 'https://download.data.grandlyon.com/wms/grandlyon',
                version: '1.3.0',
                projection: 'EPSG:3946',
                format: 'image/jpeg',
            });

            // Add an WMS elevation layer (see WMSProvider* for valid options)
            var wmsImageryLayer = new itowns.ColorLayer('wms_Jmagery', {
                updateStrategy: {
                    type: itowns.STRATEGY_DICHOTOMY,
                    options: {},
                },
                source: wmsImagerySource,
            });

            view.addLayer(wmsImageryLayer);

            // Add a WMS elevation source
            var wmsElevationSource = new itowns.WMSSource({
                extent: extent,
                url: 'https://download.data.grandlyon.com/wms/grandlyon',
                name: 'MNT2012_Altitude_10m_CC46',
                projection: 'EPSG:3946',
                width: 256,
                format: 'image/jpeg',
            });

            // Add a WMS elevation layer
            var wmsElevationLayer = new itowns.ElevationLayer('wms_elevation', {
                useColorTextureElevation: true,
                colorTextureElevationMinZ: 37,
                colorTextureElevationMaxZ: 240,
                source: wmsElevationSource,
            });

            view.addLayer(wmsElevationLayer);

            var kmlSource = new itowns.FileSource({
                    url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/lyon.kml',
                    projection: 'EPSG:4326',
                    extent: extent,
                    zoom: { min: 0, max: 6 },
                    fetcher: itowns.Fetcher.xml,
                    parser: itowns.KMLParser.parse,
                });
            var kmlLayer = new itowns.ColorLayer('Kml', {
                transparent: true,
                source: kmlSource,
            });
            view.addLayer(kmlLayer);

            var gpxSource = new itowns.FileSource({
                    url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/lyon.gpx',
                    projection: 'EPSG:4326',
                    zoom: { min: 0, max: 6 },
                    fetcher: itowns.Fetcher.xml,
                    parser: itowns.GpxParser.parse,
                });
            var gpxLayer = new itowns.ColorLayer('Gpx', {
                transparent: true,
                style: {
                    stroke: 'blue',
                },
                source: gpxSource,
            });
            view.addLayer(gpxLayer);

            var geoSource = new itowns.FileSource({
                    url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/lyon.geojson',
                    projection: 'EPSG:3946',
                    extent: extent,
                    zoom: { min: 0, max: 6 },
                    fetcher: itowns.Fetcher.json,
                    parser: itowns.GeoJsonParser.parse,
                });
            var geoLayer = new itowns.ColorLayer('geo', {
                transparent: true,
                source: geoSource,
                style: {
                    fill: 'orange',
                    fillOpacity: 0.2,
                    stroke: 'white',
                },
            });

            view.addLayer(geoLayer);

            p = { coord: extent.center(), heading: -49.6, range: 6200, tilt: 17 };
            itowns.CameraUtils.transformCameraToLookAtTarget(view, view.camera.camera3D, p);

            // instanciate controls
            // eslint-disable-next-line no-new
            new itowns.PlanarControls(view, {});
        </script>
    </body>
</html>
